package com.guoyh.pronet.service.wmodel.home

import com.guoyh.baserepos.entity.base.ApiPagerResponse
import com.guoyh.baserepos.entity.wmodel.ArticleBean
import com.guoyh.baserepos.entity.wmodel.BannerBean
import com.guoyh.pronet.service.BaseService
import rxhttp.IAwait
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse

/**
 * @CreateDate: 7/24/21 5:13 PM
 * @Author: guoyh
 * @Description: 文章相关 APi
 */

val wModelArticleApi by lazy {
    WMArticleApiService.instance
}

class WMArticleApiService private constructor() : BaseService() {
    companion object {
        const val HOME_LIST = "article/list/%s/json"
        const val HOME_BANNER = "banner/json"

        val instance: WMArticleApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            WMArticleApiService()
        }
    }

    /**
     * 获取列表信息
     */
    fun getList(pageIndex: Int): IAwait<ApiPagerResponse<ArticleBean>> =
        RxHttp.get(HOME_LIST, pageIndex).toResponse()


    /**
     * 获取首页Banner
     */
    fun getBannerList(): IAwait<MutableList<BannerBean>> =
        RxHttp.get(HOME_BANNER).toResponse()

}